package com.qk.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.common.PageResult;
import com.qk.entity.Role;
import com.qk.mapper.RoleMapper;
import com.qk.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;
    @Override
    public PageResult<Role> getRoles(String name, String label, Integer page, Integer pageSize) {

        PageHelper .startPage(page,pageSize);

        List<Role> roleList = roleMapper.selectList(name,label);

        Page< Role>  pages =(Page< Role>) roleList;

        return new PageResult<>(pages.getTotal(),pages.getResult());
    }

    @Override
    public void deleteById(Integer id) {
        roleMapper.deleteById(id);
    }

    @Override
    public void add(Role role) {
        role.setCreateTime(LocalDateTime.now());
        role.setUpdateTime(LocalDateTime.now());
        roleMapper.insert(role);
    }

    @Override
    public Role getById(Integer id) {
        return roleMapper.selectById(id);
    }

    @Override
    public void update(Role role) {
        role.setUpdateTime(LocalDateTime.now());
         roleMapper.update(role);
    }

    @Override
    public List<Role> getAllList() {
        return roleMapper.getAllList();
    }


}
